/**
 * Copyright (c) 2012, SHX Studio.
 * All rights reserved.
 * rosary226@gmail.com
 * 
 * @author shenqianfeng
 * @date 2012-9-4  
 * @version 1.0   
 */
package com.xxx.sqfengine.transform;

import javax.microedition.khronos.opengles.GL10;

import com.xxx.sqfengine.util.SQFGLCompareUtil;
import com.xxx.sqfengine.util.SQFGLConstants;

/**
 * @author shenqianfeng
 */
public class SQFGLTransformManager {
	
	protected SQFGLRotateInfo mRotateInfo;
	protected SQFGLScaleInfo mScaleInfo;
	protected SQFGLTranslateInfo mTranslateInfo;
	
	public void draw(GL10 gl) {
		
		if(getTranslateInfo() != null) {
			float deltaX = getTranslateInfo().getDeltaX();
			float deltaY = getTranslateInfo().getDeltaY();
			float deltaZ = getTranslateInfo().getDeltaZ();
			if( ! SQFGLCompareUtil.isEqualZero(deltaX) ||
				! SQFGLCompareUtil.isEqualZero(deltaY) ||
				! SQFGLCompareUtil.isEqualZero(deltaZ)) {
				SQFGLConstants.logInfo("deltaX: " + deltaX + " deltaY: " + deltaY + " deltaZ: " + deltaZ + "\n");
				gl.glTranslatef(deltaX, deltaY, deltaZ);
			}
		}
		
		if(getScaleInfo() != null) {
			float scaleX = getScaleInfo().getXScaleRatio();
			float scaleY = getScaleInfo().getYScaleRatio();
			float scaleZ = getScaleInfo().getZScaleRatio();
			if(! SQFGLCompareUtil.isEqualZero(scaleX) ||
				! SQFGLCompareUtil.isEqualZero(scaleY) ||
				! SQFGLCompareUtil.isEqualZero(scaleZ)) {
				gl.glScalef(scaleX, scaleY, scaleZ);
			}
		}
		
		if(getRotateInfo() != null) {
			float degree = getRotateInfo().getDegree();
			if(! SQFGLCompareUtil.isEqualZero(degree) && 
				(SQFGLCompareUtil.isEqualOne(Math.abs(getRotateInfo().getAroundX())) || 
				 SQFGLCompareUtil.isEqualOne(Math.abs(getRotateInfo().getAroundY())) ||
				 SQFGLCompareUtil.isEqualOne(Math.abs(getRotateInfo().getAroundZ())) )
				 ) {
				gl.glRotatef(degree, getRotateInfo().getAroundX(), getRotateInfo().getAroundY(), getRotateInfo().getAroundZ());
			}
		}
	}
	
	public SQFGLRotateInfo getRotateInfo() {
		return mRotateInfo;
	}
	
	public void setRotateInfo(SQFGLRotateInfo info) {
		this.mRotateInfo = info;
	}
	
	public SQFGLScaleInfo getScaleInfo() {
		return mScaleInfo;
	}
	
	public void setScaleInfo(SQFGLScaleInfo info) {
		this.mScaleInfo = info;
	}
	
	public SQFGLTranslateInfo getTranslateInfo() {
		return mTranslateInfo;
	}
	
	public void setTranslateInfo(SQFGLTranslateInfo info) {
		this.mTranslateInfo = info;
	}
}
